

$.ajax({
    url:'/api/login',
    type:'post',
    data:{userName:'admin',password:'123456'},
    success:function(ret){
        $.ajax({
            url:'/api/getDataList',
            type:'post',
            data:{pageSize:10,pageNumber:1},
            success:function(ret){
                renderlist(ret);
            },
            error:function(err){
                alert('获取列表错误：'+err);
            }
        });
    },
    error:function(err){
        alert('登录错误：'+err);
    }
});



var login = function(user,pwd){
    return axios.post('/api/login',{
        userName:user,
        password:pwd
    });
}
var getList = function(){
    return axios.post('/api/getDataList',{});
}

var loginP = login('admin','123456');
loginP.then(function(ret){
    return getList();
}).then(function(data){
    renderList(data)
}).catch(function(err){
    alert('获取列表错误：'+err);
});

loginP.catch(function(err){alert('登录错误：'+err)})



// 发送 POST 请求

axios({
    method: 'post',
    url: '/user/12345',
    data: {
        firstName: 'Fred',
        lastName: 'Flintstone'
    }
})
.then(function(ret){
    console.log(ret);
})
.catch(function(err){
    console.log(err)
});


//传统ajax调用


$.ajax({
    url:'/user/12345',
    type:'post',
    data: {
        firstName: 'Fred',
        lastName: 'Flintstone'
    },
    success:function(ret){
        console.log(ret)
    },
    error:function(err){
        console.log(err)
    }
});
//并发请求完成判定
var done = 0;
$.ajax({
    url:'/api/news',
    success(ret){
        done++;
        if(done>=3){
            console.log('所有数据加载完成！')
        }
    }
});
$.ajax({
    url:'/api/productList',
    success(ret){
        done++;
        if(done>=3){
            console.log('所有数据加载完成！')
        }
    }
});
$.ajax({
    url:'/api/notice',
    success(ret){
        done++;
        if(done>=3){
            console.log('所有数据加载完成！')
        }
    }
});

var req1 = axios({
    method:'get',
    url:'/api/news'
});
var req2 = axios({
    method:'get',
    url:'/api/productList'
});
var req3 = axios({
    method:'get',
    url:'/api/notice'
});
axios.all([req1,req2.req3]).then(function(ret){
    console.log('所有数据加载完成！')
})



new Vue({
    data () {
        return {
            count: 0
        }
    },
    template: '<div @click="increment">{{ count }}</div>',
    methods: {
        increment () {
            this.count++
        }
    }
})



//启动应用，挂到dom节点#app
new Vue({
    router: router,
    store,
    render: h => h(App)
}).$mount('#app')

//路由配置
const routes = [
  { path: '/',name:'home',redirect:'/counter'},
  { path: '/counter',name:'counter',component:Couter},
  { path: '/contact',name:'contact',component:Wrapper,children:[
    {path:'',redirect:'/contact/list'},
    {path:'list',name:'contactlist',component:ContactList},
    {path:'detail/:contactId',name:'contactdetail',component:ContactDetail},
    {path:'add',name:'contactadd',component:ContactAdd},
    {path:'edit/:contactId',name:'contactedit',component:ContactEdit},
  ]}
]
//生成一个路由实例
const router = new VueRouter({
  mode: 'history', //默认是hash路由
  routes
});


export default router;






